package view;

import java.io.File;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class StatusBar extends JPanel {	
	
	private static final long serialVersionUID = 1L;
	
	public StatusBar() {		
		infoDir = new JLabel();		
		infoDir.setText("");	
		this.add(infoDir);
	}
	
	public StatusBar(File file) {
		
		infoDir = new JLabel();		
		infoDir.setText(generateStatistic(file));
		infoDir.setHorizontalAlignment(JTextField.LEFT);	
		this.add(infoDir);
	}
	
	public String generateStatistic(File file) {
		File [] files = file.listFiles();		
		int d = 0;
		int f = 0;	
		
		if (files != null) {
			
			for (int  i=0 ; i< files.length ; i++) {
				if (files[i].isDirectory()) {
					d += 1;
				} else if ( files[i].isFile()) {
					f += 1;
				}			
			}		
			return f + " file(s), " + d + " directory(s)";		
		}
		return  "";
	}
	
	
	
	public void setInfoDir(File file) {
		infoDir.setText(generateStatistic(file));		
	}
	
	private JLabel infoDir;
	

}
